# coding:utf-8
"""
So far we have created a child class that inherits
the properties and methods from its parent.
We want to add the __init__() function to
the child class (instead of the pass keyword).
Note: The __init__() function is called automatically
every time the class is being used to create a new object.
"""
class Person:
def __init__(self, fname, lname):
self.firstname = fname
self.lastname = lname
def printname(self):
print(self.firstname, self.lastname)
"""
When you add the __init__() function,
the child class will no longer inherit the parent's __init__() function.
The child's __init__() function
overrides(็กๅนใใ) the inheritance of the parent's __init__() function.
To keep the inheritance of the parent's __init__() function,
add a call to the parent's __init__() function:
class Student(Person):
def __init__(self, fname, lname):
Person.__init__(self, fname, lname)
"""
#override case1
class Student(Person):
def __init__(self, fname):
self.firstname = fname
def printname(self):
print(self.firstname)
x = Student("Gorge")
x.printname()
#override case2
class Student(Person):
def __init__(self, fname, mname,lname):
Person.__init__(self, fname, lname)
self.middlename = mname
def printname(self):
print(self.firstname,self.middlename,self.lastname)
x = Student("Gorge","Ben","Bridgeton")
x.printname()